//https://blog.51cto.com/u_15656645/5373369
//https://leetcode.cn/studyplan/top-100-liked/
//动态规划变种
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <string>
#include <unordered_map>
#include <algorithm>

using namespace std;

class Solution {
public:
    static bool f(vector<int>&a,vector<int>&b)
    {
        return a[0]<b[0];
    }
    vector<vector<int>> merge(vector<vector<int>>& a) {
        vector<vector<int>>res;
        if(a.empty()) return res;
        
        sort(a.begin(),a.end(),f); //排序
        
        int l = a[0][0], r = a[0][1];
        for(int i = 1; i < a.size(); i++)
        {
            if(a[i][0] > r)  //上一个区间为独立区间
            {
                res.push_back({l,r});
                l = a[i][0], r = a[i][1];
            }
            else r = max(r,a[i][1]); //区间合并，更新右端点
        }
        res.push_back({l,r}); 
        return res;
    }
};